package com.yzh.booksystem.utils;

import com.mchange.v2.c3p0.ComboPooledDataSource;

;import javax.sql.DataSource;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;

//public class Utils {
//    //通过new一个ComboPooledDataSource（datasource实现类）带参数的构造方法根据配置文件获取数据源对象
//    private static ComboPooledDataSource ds = new ComboPooledDataSource("yzh");
//
//    public static DataSource getDataSource(){
//        return ds;
//    }//public让其他类访问，static通过类名访问
//
//    public static void main(String[] args) throws SQLException {
//        System.out.println(ds.getConnection());
//        //getMetaData()是connection对象的方法，connection对象是connection接口类型，元数据对象类型是DatabaseMetaData类
//        DatabaseMetaData metaData = ds.getConnection().getMetaData();
//        System.out.println(metaData.getURL());
//        System.out.println(ds.getConnection());
//        DatabaseMetaData metaData1 = ds.getConnection().getMetaData();
//        System.out.println(metaData.getURL() + "\t" + metaData.getUserName());
//
//    }
//}

public class Utils {
    private static ComboPooledDataSource ds = new ComboPooledDataSource("yzh");
    public static DataSource getDataSource() {
        return ds;
    }


    public static void main(String[] args) throws SQLException {
        System.out.println(ds.getConnection());
        DatabaseMetaData metaData = ds.getConnection().getMetaData();
        System.out.println(metaData.getURL() + "\t" + metaData.getUserName());
    }
}
//public class Utils {
//    private static ComboPooledDataSource ds = new ComboPooledDataSource("yzh");
//
//    public static DataSource getDataSource() {
//        return ds;
//    }
//}